<?php

class WidgetFormDatePick extends sfWidgetForm
{

	public function configure($options = array(), $attributes = array())
	{
		$this->addOption('template.javascript',
<<<EOF

<script type="text/javascript">
/* <![CDATA[ */
	{input.id}_cal = new JsDatePick({
		useMode:2,
		target:"{input.id}",
		dateFormat: "%Y-%m-%d",
		cellColorScheme: "armygreen"
	});
/* ]]> */
</script>

EOF
		);
	}

	public function getJavascripts()
	{
		return array('jsDatePick.min.1.3.js');
	}

	public function getStyleSheets()
	{
		return array('datepick/jsDatePick_ltr.min.css' => 'all'); 
	}

	public function render($name, $value = null, $attributes = array(), $errors = array())
	{
		if($value === null)
			$vale = '';

		$template_vars = array(
			'{input.id}' => $this->generateId($name)
		);

		$attributes['id'] = $template_vars['{input.id}'];

		$input = $this->renderTag('input', array_merge(array('type' => 'text', 'name' => $name, 'value' => $value), $attributes));

		return strtr($input . $this->getOption('template.javascript'), $template_vars);
	}

}
